<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.7.3/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>
<body>
<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container">
    <div class="layuimini-main">
<div class="layuimini-container layuimini-page-anim" >
    <div class="layuimini-main">
        <form class="layui-form myData" action="save" method="post" lay-filter="stuform" id="save">
            <input type="hidden" name="id"  id="id"/>
            <div class="layui-form-item">
                <label class="layui-form-label">host：</label>
                <div class="layui-input-block">
                    <input type="text" name="host" lay-verify="required"  class="layui-input" id="host"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" name="userName" lay-verify="required"  id="userName" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="required"  id="password" class="layui-input" />
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="save">保存</button>
                </div>
            </div>
        </form>
        <button class="layui-btn layui-btn-normal" onclick="show()">如何配置?</button>
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="testSend" onclick="testSend()">校验邮箱</button>
        校验邮箱是否可用后才可使用定时任务
        <span class="layui-badge layui-bg-orange" id="state">未校验</span>

    </div>
</div>
    </div>
</div>
<script src="../../lib/layui-v2.7.3/layui/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../../api/urlConfig.js"></script>
<script>
    // 初始化
    $(function () {
        $.ajax({
            url: ipURL + '/caption/email-setting',
            type: 'GET',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
               $("#id").val(data.data.data.id);
               $("#userName").val(data.data.data.userName);
               $("#host").val(data.data.data.host);
               $("#password").val(data.data.data.password);
               console.log(data.data.data.state == true)
               $("#state").text(data.data.data.state == true ? "已校验" : "未校验");
            },
        });
    })


    function show(){
        layer.open({
            type: 1,
            area: ['800px', '550px'],
            content: $('#hint'),
            btn: ['退出'],
            end:function(){
                $('#hint').css('display','none')
            },
        })
    }
    function testSend(){
        $.ajax({
            url: ipURL + '/caption/email-setting//testSend',
            type: 'get',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                layer.msg(data.message)
            },
        });

        return false;
    }
    layui.use('form', function(){
        var form = layui.form;

        //提交事件
        form.on('submit(save)', function(data){
            $.ajax({
                url: ipURL + '/caption/email-setting',
                type: 'put',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType: 'application/json;charset=UTF-8',
                beforeSend: function (request) {
                    request.setRequestHeader("token", localStorage.token);
                },
                success: function (data) {
                    var d = data.data.data
                    layer.msg(data.message)
                    $("#id").val(d.id);
                    $("#userName").val(d.userName);
                    $("#host").val(d.host);
                    $("#password").val(d.password);
                },
            });

            return false;
        });



    });


</script>
</body>
<div id="hint" style="display: none">
    <blockquote class="layui-elem-quote">QQ邮箱示例:</blockquote>
    <blockquote class="layui-elem-quote layui-quote-nm">第一步: 打开QQ邮箱</blockquote>

    <blockquote class="layui-elem-quote layui-quote-nm">第二步: 点击账户</blockquote>

    <img src="../../images/email-01.jpg">
    <blockquote class="layui-elem-quote layui-quote-nm">第三步: 开启POP3/SMTP服务</blockquote>
    <img src="../../images/email-02.jpg">
    <blockquote class="layui-elem-quote layui-quote-nm">第四步: 获取授权码</blockquote>
    <fieldset class="layui-elem-field">
        <legend>第五步: 填写邮箱配置</legend>
        <div class="layui-field-box">
            host: smtp.qq.com
            <br>
            用户名: 自己的邮箱
            <br>
            密码: 授权码
        </div>
    </fieldset>
</div>
</html>